<?php

/*
 * This file contains the class definition for a DAOFactory. Its purpose
 * is to serve up a DAO for a database table whose name will be specified
 * on-the-fly in the calling application.
 */

class DAOFactory {
        
    /**
     * Method: makeDAO
     * 
     * @param string $databaseTableName
     * The name of a database table to obtain a DAO for.
     * This parameter is case-sensitive.
     * 
     * @return BaseDAO A DAO that inherits from the BaseDAO class and provides
     * manipulators for the specified database table.
     * 
     * @throws Exception if a corresponding DAO object cannot be found for the
     * specified database table.
     */
    public static function makeDAO($databaseTableName) {
        
        $DAOProduct;
        
        // TODO (phengheong@hotmail.com, 17 Jan 2013) Consider using reflection
        // to construct the appropriate DAO, instead of the switch-case block below.
        
        switch($databaseTableName) {
            case "suggestion":
                $DAOProduct = new SuggestionDAO();
                break;
            
            case "account":
                $DAOProduct = new AccountDAO();
                break;
            
            default:
                throw new Exception("No DAO exists for the database table $databaseTableName");
        }
        
        // The execution flow will only reach here if the exception
        // above has not been thrown.
        return $DAOProduct;
    }
}

?>
